Barcode Xpress for ActiveX v13 - Updated
Tutorial: Create Your First Project
User Guide > Getting Started > Tutorial: Create Your First Project
These step-by-step tutorials will guide you to build a complete application that analyzes a 1D barcode from an image and output the value and type the terminal. The tutorials are for:

C++

Prerequisites:

Steps:

  1. Launch VC++ (below project has been tested in VS2013).
  2. Create a new CLR Empty project and name it BXTutorial.
  3. Add Windows Form to this project.
    1. Right-click on the project and select Add > New Item.
    2. Select UI > Windows Form, its default name is MyForm.
  4. Set application entry point.
    1. Add below code to MyForm.cpp:
      C++
      Copy Code
      #include "MyForm.h"
      using namespace System;
      using namespace System::Windows::Forms;
      [STAThread]
      void main(array<String^>^ args) {
           Application::EnableVisualStyles();
           Application::SetCompatibleTextRenderingDefault(false);
           BXTutorial::MyForm form;
           Application::Run(%form);
      }
      
    2. Right-click your project in the Solution Explorer and click Properties.
    3. Under Configuration Properties > Linker > Advanced, change Entry Point to "main" (without quotation marks).
    4. Under Configuration Properties > Linker > System, change SubSystem to Windows (/SUBSYSTEM/WINDOWS).
  5. Add ActiveX component to this project.
    1. Open the design view, right-click on the Toolbox panel and select Choose Items…
    2. On the dialog, go to the tab COM Components.
    3. Add Accusoft BarcodeXpress 13 and Accusoft ImagXpress 13 to your toolbox
    4. Drag the two controls to MyForm.
    5. Drag OpenFileDialog from Toolbox > Dialogs to MyForm.
    6. Select the component ImageXpress and set the property CtlAutoSize to ISIZE_BestFit.
  6. Add menu to MyForm
    1. From Toolbox > Menu&Toolbars, select MenuStrip and add to MyForm.
    2. Add a menu, "File",  and sub menu, "Open", named mnuOpen.
    3. Add an additional sub menu, "Exit", named mnuExit.
    4. Double-click on Open and add the code below:
      C++
      Copy Code
      private: System::Void mnuOpen_Click(System::Object^  sender, System::EventArgs^  e) {
           if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
           {
                axImagXpress1->FileName = openFileDialog1->FileName;
           }
       }
      
    5. From the design window, double-click on Exit and add the code below:
      C++
      Copy Code
      private: System::Void mnuExit_Click(System::Object^  sender, System::EventArgs^  e) {
           Application::Exit();
      }
      
  7. Add button to MyForm.
    1. Add one button from Toolbox, set the name to btnReadBarcode and set Text to "Read 1D Barcode".
    2. Double-click on that button and add below code:
      C++
      Copy Code
      private: System::Void btnReadBarcode_Click(System::Object^  sender, System::EventArgs^  e) {
           // Set barcode type to BC_StyleUnknown value  - Barcode Xpress engine will search for all 1D barcodes.
           axBarcodeXpress1->SetBarcodeReaderType(BC_StyleUnknown);
           // Set the read region of interest to all zero
           // so the entire images is searched.
           axBarcodeXpress1->ReaderAreaHeight = 0;
           axBarcodeXpress1->ReaderAreaWidth = 0;
           axBarcodeXpress1->ReaderAreaX = 0;
           axBarcodeXpress1->ReaderAreaY = 0;
      
           if (axImagXpress1->hDIB == 0)
           {
                MessageBox::Show("Error: You must select an image!");
                return;
           }
       
           axBarcodeXpress1->AnalyzehDib(axImagXpress1->hDIB);
           int numBC = axBarcodeXpress1->NumBarcodes;
           String^ bcName;
           String^ bcResult;
           String^ result;
      
           for (int i = 0; i < numBC; i++)
           {
                axBarcodeXpress1->GetBarcode(i);
                bcName = axBarcodeXpress1->BarcodeCodeName;
                bcResult = axBarcodeXpress1->BarcodeResult;
                result += "#" + i.ToString() + " Type: " + bcName + " Value: " + bcResult + "\n";
           }
           MessageBox::Show(result);
      }
      
  8. Registration.
    1. To register Barcode Xpress and ImagXpress, add the following code to MyForm.h:
      C++
      Copy Code
      MyForm(void)
      {
           InitializeComponent();
           // The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey method must be called to distribute the runtime.  Note that the SolutionName, SolutionKey and OEMLicenseKey values shown below are only examples.
           //axBarcodeXpress1->SetSolutionName("YourSolutionName");
           //axBarcodeXpress1->SetSolutionKey(12345, 12345, 12345, 12345);
           //axBarcodeXpress1->SetOEMLicenseKey("1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation...");
           //axImagXpress1->SetSolutionName("YourSolutionName");
           //axImagXpress1->SetSolutionKey(12345, 12345, 12345, 12345);
           //axImagXpress1->SetOEMLicenseKey("1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation...");
      }
      
  9. Run the project.
    1. Select File > Open and choose one image with a 1D barcode on it.
    2. Click the Read 1D Barcode button.
    3. A dialog with the barcode result displays. 

VB6

Prerequisites:

Steps:

The example code below includes function header and footer.
  1. Launch VB6 with administrator’s permission.
  2. Create a Standard EXE project.
  3. Add BX13, IX13 and Common Dialog component to this project.
    1. Go to menu Project\Componets…
    2. Select Accusoft Barcode Xpress v13.2, Accusoft ImageXpress 13.0 and Microsoft Common Dialog Control 6 (SP6). Click Ok.
    3. Double-click the three new icons and add them to Form1.
    4. Click the ImagXpress control and set property AutoSize to value “4 - ISIZE_BestFit”.
  4. Add Menu:
    1. Right-click on the panel of Form1 and select Menu Editor.
    2. Add a menu, "File",  and sub menu, "Open", named mnuOpen.
    3. Add an additional sub menu, "Exit", named mnuExit.
    4. Add below code for File > Open:
      VB
      Copy Code
      Private Sub mnuOpen_Click()
          With CommonDialog1
              .CancelError = True
              .DialogTitle = "Open 1-bit, 8-bit or 24-bit Image File"
              .Filter = "TIFF (*.tif)|*.tif|BMP (*.bmp)|*.bmp|All Files (*.*) |*.*"
              .InitDir = App.Path & "\..\..\..\..\..\..\Common\Images\"
              .Action = 1
          End With
        
          With ImagXpress1
              .FileName = CommonDialog1.FileName
              If .FileName = "" Then
                  MsgBox "Please pick a filename"
              End If
              '.Width = 6900
              '.Height = 4000
          End With
      End Sub
      
  5. Add below code for File >Exit:
    VB
    Copy Code
    Private Sub mnuExit_Click()
        End
    End Sub
    
  6. Add Free memory function to Form 1:
    VB
    Copy Code
    Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
    
  7. Add a button to Form1. Then set its Caption to "Read 1D Barcode" and Name to "btnRead1DBarcode".
  8. Add below code for the click event:
    VB
    Copy Code
    Private Sub btnRead1DBarcode_Click()
        Dim result As String
        Dim i As Long
        Dim hDib As Long
      
        If ImagXpress1.hDib = 0 Then
            MsgBox ("No file loaded")
        Else
            Me.MousePointer = vbHourglass
            DoEvents
          
            hDib = ImagXpress1.CopyDIB
          
            BarcodeXpress1.AnalyzehDib hDib 
            BarcodeXpress1.SetBarcodeReaderType BC_StyleUnknown   'set barcode type to BC_StyleUnknown value - Barcode Xpress engine will search for all 1D barcodes.
            If BarcodeXpress1.NumBarcodes > 0 Then
                For i = 0 To BarcodeXpress1.NumBarcodes - 1
                    BarcodeXpress1.GetBarcode i
                    result = result & "Barcode #" & i & Chr$(13) & _
                        "Barcode value = " & BarcodeXpress1.BarcodeResult & Chr$(13) & _
                        "Barcode type = " & BarcodeXpress1.BarcodeCodeName & Chr$(13)
                Next i
                MsgBox result
            Else
                MsgBox "No barcodes were found.  Error = " & BarcodeXpress1.SSError & ".  " & BarcodeXpress1.SSErrorMsg, , _
                        "Smartscan Xprebarcodexpress1 Barcode Sample"
            End If
          
            '*****Call the GlobalFree function to "free" the barcode hDib
            GlobalFree hDib
            Me.MousePointer = vbDefault
            DoEvents
       End If
    End Sub
    
  9. Register the product. If you have a license, you can fill your license information in the below code:
    VB
    Copy Code
    Private Sub Form_Load()
       
         ' The SetSolutionName, SetSolutionKey and possibly the SetOEMLicenseKey method must be
         ' called to distribute the runtime.  Note that the SolutionName, SolutionKey and
         ' OEMLicenseKey values shown below are only examples.
         'BarcodeXpress1.SetSolutionName "YourSolutionName"
         'BarcodeXpress1.SetSolutionKey 12345, 12345, 12345, 12345
         'BarcodeXpress1.SetOEMLicenseKey "1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation..."
         '
         'ImagXpress1.SetSolutionName "YourSolutionName"
         'ImagXpress1.SetSolutionKey 12345, 12345, 12345, 12345
         'ImagXpress1.SetOEMLicenseKey "1.0.AStringForOEMLicensingContactAccusoftSalesForMoreInformation..."
       
     End Sub
    
  10. Run the project
    1. Select File > Open and select one image with a 1D barcode on it.
    2. Click the Read 1D Barcode button.
    3. A dialog with the barcode result will displays.